"use strict";
cc._RF.push(module, '56f5a5LrsBILJ3/EsbKni/Q', 'monster_node_info');
// scripts/monster_node_info.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AudioManager"),
    s = e("PureHelper"),
    l = e("Game"),
    _ = e("RoleSoldierInfo"),
    c = e("Toast"),
    d = e("node_team"),
    h = e("role_node"),
    u = cc._decorator,
    p = u.ccclass,
    m = u.property,
    f = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.monster_ske = null, t.monster_type = l.MonsterType.red, t.monster_hp_mask = null, t.monster_level = null, t.monster_hp_label = null, t.monster_name_label = null, t.coin_system = null, t.monster_common_skill = null, t.monster_skill_one = null, t.monster_skill_two = null, t.skill_one_time = 0, t.skill_two_time = 0, t.monster_info = null, t.max_hp_num = 0, t.now_hp_num = 0, t.attack_num = 0, t.monster_id = 0, t.attack_target = null, t.moster_attack = !1, t.ack_range = 0, t.monster_move = !1, t.start_pos = null, t._monster_level = 0, t.is_die = !1, t.monster_in_dis_index = 0, t;
  }

  return nn(t, e), t.prototype.showMonsterDisInfo = function (e) {
    this.monster_in_dis_index = e;
  }, t.prototype.initView = function () {
    for (var e = this, t = 0, o = this.node.getComponentsInChildren(cc.BoxCollider); t < o.length; t++) {
      var a = o[t];
      1 == a.tag && (this.monster_common_skill = a, a.enabled = !1, this.ack_range = 1.5 * Math.abs(a.offset.x)), 2 == a.tag && (this.monster_skill_one = a, a.enabled = !1), 3 == a.tag && (this.monster_skill_two = a, a.enabled = !1);
    }

    this.start_pos = this.node.getPosition(), this.node.getComponent(d["default"]).setTeamInfo(l.TeamInfo.rest_team), this.monster_ske.setAnimation(0, "battle_idle", !0), this.monster_info = _["default"].moster_info[this.monster_type - 1];
    var n = i.GlobalParams.MonsterDisNum[this.monster_in_dis_index];
    this._monster_level = n.num + 1, this._monster_level > this.monster_info.hp.length && (this._monster_level = this.monster_info.hp.length, n.num -= 1), this.monster_level.string = "" + this._monster_level, this.monster_name_label.string = "" + this.monster_info.name, this.max_hp_num = this.monster_info.hp[n.num], this.now_hp_num = this.max_hp_num, this.attack_num = this.monster_info.attack[n.num], this.monster_hp_mask.width = 270, this.monster_hp_label.string = "" + this.now_hp_num, this.monster_id = 10 + this.monster_type, this.node.scaleX *= this.node.x < 0 ? 1 : -1, this.monster_name_label.node.scaleX = this.monster_hp_label.node.scaleX = this.node.scaleX, this.monster_ske.setCompleteListener(function (t, o) {
      e.monsterSkinCompleteListener(t, o);
    }), this.coin_system.node.active = !1;
  }, t.prototype.mosnterMove = function (e) {
    var t = this;

    if (i.GlobalParams.GameStart && this.monster_move) {
      "run" != this.monster_ske.animation && this.playAnimation("run", !0), 0 != e.x && (this.node.scaleX = Math.abs(this.node.scaleX) * (e.x < 0 ? 1 : -1), this.monster_name_label.node.scaleX = this.monster_hp_label.node.scaleX = this.node.scaleX);
      var o = this.node.getPosition().add(e.mul(30));
      this.attack_target && cc.isValid(this.attack_target, !0) ? cc.tween(this.node).to(i.GlobalParams.GameUpdateTime, {
        position: cc.v2(o.x, o.y)
      }).call(function () {
        t.mosterAttackSkill();
      }).start() : cc.tween(this.node).to(i.GlobalParams.GameUpdateTime, {
        position: cc.v2(o.x, o.y)
      }).call(function () {
        Math.abs(s["default"].Distance(t.node.getPosition(), t.start_pos)) < 50 ? (t.monster_move = !0, t.node.scaleX = t.monster_type == l.MonsterType.red ? -1 : 1, t.monster_name_label.node.scaleX = t.monster_hp_label.node.scaleX = t.node.scaleX, t.node.setPosition(t.start_pos), t.playAnimation("battle_idle", !0), t.now_hp_num = t.max_hp_num, t.monster_hp_mask.width = 270, t.monster_hp_label.string = "" + t.now_hp_num, t.attack_target = null, t.moster_attack = !1) : t.mosnterMove(e);
      }).start();
    }
  }, t.prototype.attackMonster = function (e, t, o) {
    if (this.attack_target = o, this.moster_attack || (this.moster_attack = !0, this.mosterAttackSkill()), this.now_hp_num -= e, this.emitEvent(n["default"].SEND_SHOW_BE_HIT_INFO, {
      attack: e,
      my_team: 0,
      end_pos: cc.v2(this.node.getPosition().x, this.node.getPosition().y + 80)
    }), this.now_hp_num = this.now_hp_num < 0 ? 0 : this.now_hp_num, this.monster_hp_mask.width = 270 * this.now_hp_num / this.max_hp_num, this.monster_hp_label.string = "" + this.now_hp_num, this.now_hp_num <= 0 && !this.is_die) {
      if (this.is_die = !0, this.emitEvent(n["default"].SEND_ROLE_BE_KILL_INFO, {
        kill: t,
        be_kill: this.monster_id,
        team: l.TeamInfo.rest_team
      }), this.coin_system.node.active = !0, r["default"].getInstance().playFx("bome_coin"), this.coin_system.resetSystem(), this.monster_type == l.MonsterType.red ? (this.attack_target.getComponent(h["default"]).addRoleEffects(l.RoleEffectType.red_buff), c["default"].showNewToast(this.monster_info.name + "之力")) : this.monster_type == l.MonsterType.bule ? (this.attack_target.getComponent(h["default"]).addRoleEffects(l.RoleEffectType.blue_buff), c["default"].showNewToast(this.monster_info.name + "之力")) : this.monster_type == l.MonsterType.big_dragon && (this.emitEvent(n["default"].SEND_ROLE_ADD_BIG_DRAGON_BUFF, this.attack_target.getComponent(h["default"]).match_game_index), c["default"].showNewToast(this.monster_info.name + "之力")), r["default"].getInstance().playFx("monster_die"), this.monster_type == l.MonsterType.dragon || this.monster_type == l.MonsterType.big_dragon) {
        var a = {
          team: this.attack_target.getComponent(d["default"]).getTeamInfo(),
          id: this.monster_type == l.MonsterType.dragon ? l.SoldierType.dragon_soldier : l.SoldierType.super_dragon_soldier,
          level: this._monster_level
        };
        this.emitEvent(n["default"].SEND_CREATE_MONSTER_SOLDIER_INFO, a);
      }

      this.playAnimation("death", !1);
    }
  }, t.prototype.mosterAttackSkill = function () {
    if (cc.isValid(this.attack_target, !0) && !this.is_die) if (Math.abs(s["default"].Distance(this.node.getPosition(), this.attack_target.getPosition())) < this.ack_range) Math.abs(this.attack_target.y - this.node.y) > 50 ? (this.monster_move = !0, this.mosnterMove(cc.v2(0, this.attack_target.y > this.node.y ? 1 : -1))) : (this.monster_move = !1, this.node.scaleX = this.node.x > this.attack_target.x ? 1 : -1, this.monster_name_label.node.scaleX = this.monster_hp_label.node.scaleX = this.node.scaleX, this.AISpecialSkill());else {
      this.monster_move = !0;
      var e = cc.v2(this.attack_target.x, this.attack_target.y).sub(this.node.getPosition()).normalize();
      this.mosnterMove(e);
    }
    cc.isValid(this.attack_target, !0) || (this.attack_target = null, this.monster_move = !0, e = cc.v2(this.start_pos.x, this.start_pos.y).sub(this.node.getPosition()).normalize(), this.mosnterMove(e));
  }, t.prototype.AISpecialSkill = function () {
    this.skill_one_time <= 0 && this.monster_skill_one ? this.monsterSpecialSkillOne() : this.skill_two_time <= 0 && this.monster_skill_two ? this.monsterSpecialSkillTwo() : this.monsterAttackInfo("attack");
  }, t.prototype.monsterSpecialSkillOne = function () {
    this.monsterAttackInfo("attack_skill1"), this.monster_type == l.MonsterType.big_dragon && this.emitEvent(n["default"].SEND_PLAYER_SHOOT_WOINDE_ANIME);
  }, t.prototype.monsterSpecialSkillTwo = function () {
    this.monsterAttackInfo("attack_skill2");
  }, t.prototype.monsterAttackInfo = function (e) {
    var t = this,
        o = this.monster_ske.setAnimation(0, e, !0);
    this.monster_ske.setTrackEventListener(o, function () {
      t.monstrtCommonSkill(!1, e), t.monstrtCommonSkill(!0, e);
    });
  }, t.prototype.monsterSkinCompleteListener = function (e) {
    var t = e.animation ? e.animation.name : "";
    -1 != ["attack", "attack_skill1", "attack_skill2"].indexOf(t) && (this.monstrtCommonSkill(!1, t), this.monster_ske.timeScale = 1, this.monster_ske.clearTracks(), this.playAnimation("battle_idle", !0), this.skillCoolingTime(t)), "death" == t && (i.GlobalParams.MonsterDisNum[this.monster_in_dis_index].num++, i.GlobalParams.MonsterDisNum[this.monster_in_dis_index].time = this.monster_info.revive_time, i.GlobalParams.MonsterDisNum[this.monster_in_dis_index].exist = !1, this.node.destroy());
  }, t.prototype.skillCoolingTime = function (e) {
    var t = this;
    "attack_skill1" == e ? (this.skill_one_time = 5, this.scheduleOnce(function () {
      t.skill_one_time = 0;
    }, this.skill_one_time)) : "attack_skill2" == e && (this.skill_two_time = 12, this.scheduleOnce(function () {
      t.skill_two_time = 0;
    }, this.skill_two_time)), this.mosterAttackSkill();
  }, t.prototype.monstrtCommonSkill = function (e, t) {
    this.monster_common_skill.enabled = e && "attack" == t, this.monster_skill_one && (this.monster_skill_one.enabled = e && "attack_skill1" == t), this.monster_skill_two && (this.monster_skill_two.enabled = e && "attack_skill2" == t);
  }, t.prototype.playAnimation = function (e, t) {
    "death" != this.monster_ske.animation && this.monster_ske.setAnimation(0, e, t);
  }, t.prototype.onCollisionEnter = function (e, t) {
    var o = e.node,
        a = o.group;

    if (!cc.isValid(o, !0) || 1 != t.tag && 2 != t.tag && 3 != t.tag || 0 != e.tag || "role" == a && o.getComponent(h["default"]).roleBeHit(this.attack_num, this.monster_id), "map" == a && 0 == t.tag && 88 == e.tag) {
      this.attack_target = null, this.monster_move = !0, this.moster_attack = !1;
      var n = cc.v2(this.start_pos.x, this.start_pos.y).sub(this.node.getPosition()).normalize();
      this.mosnterMove(n);
    }
  }, oo([m(sp.Skeleton)], t.prototype, "monster_ske", void 0), oo([m({
    type: cc.Enum(l.MonsterType),
    displayName: "野怪类型"
  })], t.prototype, "monster_type", void 0), oo([m(cc.Node)], t.prototype, "monster_hp_mask", void 0), oo([m(cc.Label)], t.prototype, "monster_level", void 0), oo([m(cc.Label)], t.prototype, "monster_hp_label", void 0), oo([m(cc.Label)], t.prototype, "monster_name_label", void 0), oo([m(cc.ParticleSystem)], t.prototype, "coin_system", void 0), oo([p], t);
}(a["default"]);

o["default"] = f;

cc._RF.pop();